package com.star.mentor.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.star.core.base.BaseController;
import com.star.mentor.dto.EvaluationLogPageDTO;
import com.star.mentor.dto.EvaluationPageDTO;
import com.star.mentor.dto.EvaluationSaveDTO;
import com.star.mentor.dto.EvaluationUpdateDTO;
import com.star.mentor.service.EvaluationLogService;
import com.star.mentor.service.EvaluationService;
import com.star.mentor.vo.EvaluationDetailVO;
import com.star.mentor.vo.EvaluationLogPageVO;
import com.star.mentor.vo.EvaluationPageVO;
import com.star.security.annotations.Authorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 评估规则
 *
 * @author yangzj
 */
@RestController
@RequestMapping("/evaluation")
public class EvaluationController extends BaseController {

    @Autowired
    private EvaluationService evaluationService;
    @Autowired
    private EvaluationLogService evaluationLogService;

    /**
     * 保存
     *
     * @param dto 入参
     */
    @Authorize("evaluation:all")
    @PostMapping
    public void save(@Validated @RequestBody EvaluationSaveDTO dto) {
        evaluationService.save(dto);
    }

    /**
     * 更新
     *
     * @param dto 入参
     */
    @Authorize("evaluation:all")
    @PutMapping
    public void update(@Validated @RequestBody EvaluationUpdateDTO dto) {
        evaluationService.update(dto);
    }

    /**
     * 更新启用
     *
     * @param id      ID
     * @param enabled 启用
     */
    @Authorize("evaluation:all")
    @PutMapping("/enabled/{id}/{enabled}")
    public void updateEnabled(@PathVariable("id") Long id, @PathVariable("enabled") boolean enabled) {
        evaluationService.updateEnabled(id, enabled);
    }

    /**
     * 删除通过ID
     *
     * @param id ID
     */
    @Authorize("evaluation:all")
    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable("id") Long id) {
        evaluationService.deleteById(id);
    }

    /**
     * 分页
     *
     * @param dto 入参
     * @return {@link IPage}<{@link EvaluationPageVO}>
     */
    @Authorize("evaluation:all")
    @PostMapping("/page")
    public IPage<EvaluationPageVO> page(@Validated @RequestBody EvaluationPageDTO dto){
        return evaluationService.page(dto);
    }

    /**
     * 获取详情
     *
     * @param id ID
     * @return {@link EvaluationDetailVO}
     */
    @Authorize("evaluation:all")
    @GetMapping("/{id}")
    public EvaluationDetailVO getDetail(@PathVariable("id") Long id){
        return evaluationService.getDetail(id);
    }

    /**
     * 分页
     *
     * @param dto 入参
     * @return {@link IPage}<{@link EvaluationLogPageVO}>
     */
    @Authorize("evaluation:all")
    @PostMapping("/log/page")
    public IPage<EvaluationLogPageVO> pageLog(@Validated @RequestBody EvaluationLogPageDTO dto){
        return evaluationLogService.page(dto);
    }
}
